//
//  ViewController.swift
//  ChangeSkin
//
//  Created by Lenhulk on 2016/11/20.
//  Copyright © 2016年 Lenhulk. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    // MARK: - 属性
    @IBOutlet weak var skinBarTopCons: NSLayoutConstraint!
    @IBOutlet weak var bgImageView: UIImageView!
    @IBOutlet weak var iconButton: UIButton!
    @IBOutlet weak var textLabel: UILabel!

    // MARK: - 系统回调函数
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setCurrentSkin()
    }

}


extension ViewController {
    
    // MARK: - 点击皮肤对应的Button
    @IBAction func skinBtnClick(_ sender: UIButton) {
        switch sender.tag {
        case 0:
            SkinTools.setCurrentSkinName("guoqing")
            setCurrentSkin()
        case 1:
            SkinTools.setCurrentSkinName("zhongqiu")
            setCurrentSkin()
        case 2:
            SkinTools.setCurrentSkinName("chunjie")
            setCurrentSkin()
        default:
            print("你点的哪里?")
        }
        showSkinBar()
    }
    
    // MARK: - 换肤方法
    fileprivate func setCurrentSkin (){
        //切换皮肤图
        bgImageView.image = SkinTools.imageName("back.png")
        iconButton.setImage(SkinTools.imageName("icon.png"), for: .normal)
        //切换lebel背景
        textLabel.backgroundColor = SkinTools.labelBgColor()
    }
    
    // MARK: - 控制换肤ToolBar
    @IBAction func showSkinBar() {
        skinBarTopCons.constant = skinBarTopCons.constant == 0 ? -44 : 0
        UIView.animate(withDuration: 0.35, animations: {
            self.view.layoutIfNeeded()      //刷新界面
        })
    }
}

